﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetFrameworkExtensions.Converters
{
  public class StringToStringConverter : ItemConverterBase<String, String>
  {
    public static readonly StringToBooleanConverter Default = new StringToBooleanConverter();

    public override bool TryConvert(string item, out string result)
    {
      result = item;
      return true;
    }
  }

  public class StringToBooleanConverter : ItemConverterBase<string, bool>
  {
    public static readonly StringToBooleanConverter Default = new StringToBooleanConverter();

    public override bool TryConvert(string item, out bool result)
    {
      return Boolean.TryParse(item, out result);
    }
  }

  public class BooleanToStringConverter : ItemConverterBase<bool, string>
  {
    public static readonly BooleanToStringConverter Default = new BooleanToStringConverter();

    public override bool TryConvert(bool item, out string result)
    {
      result = item.ToString();
      return true;
    }
  }

  public class StringToByteConverter : ItemConverterBase<string, byte>
  {
    public static readonly StringToByteConverter Default = new StringToByteConverter();

    public override bool TryConvert(string item, out byte result)
    {
      return Byte.TryParse(item, out result);
    }
  }

  public class ByteToStringConverter : ItemConverterBase<byte, string>
  {
    public static readonly ByteToStringConverter Default = new ByteToStringConverter();

    public override bool TryConvert(byte item, out string result)
    {
      result = item.ToString();
      return true;
    }
  }

  public class StringToCharConverter : ItemConverterBase<string, char>
  {
    public static readonly StringToCharConverter Default = new StringToCharConverter();

    public override bool TryConvert(string item, out char result)
    {
      return Char.TryParse(item, out result);
    }
  }

  public class CharToStringConverter : ItemConverterBase<char, string>
  {
    public static readonly CharToStringConverter Default = new CharToStringConverter();

    public override bool TryConvert(char item, out string result)
    {
      result = item.ToString();
      return true;
    }
  }

}
